package junit;

import expressions.VariableAccess;
import instructions.ArrayAssign;
import instructions.ArrayDef;
import instructions.BadInstructionException;
import instructions.Case;
import instructions.Composition;
import instructions.Instruction;
import instructions.Local;
import instructions.Print;
import instructions.VariableAssign;
import values.Array;
import values.PatternArray;
import values.Value;
import values.Boolean;
import values.Integer;
import base.AST;
import base.Environment;
import base.Identifier;

public class TestCase {

	public static void main( String[] args) {

		/* TEST MATCH : true expected
		local(N) {
			N = [1 2]
			case N 
				of P { print(true)}			<===
				else {print(false)}
		}
		 */
		System.out.println("First Test for Pattern Matching : expected to print \"boolean:true\"");
		Identifier identname = new Identifier("N");
		Identifier identpat = new Identifier("P");

		AST[] nameArray = {new Integer(1), new Integer(2)};
		ArrayDef nameAssign = new ArrayDef(identname, nameArray);

		Print printMatch = new Print(new Boolean(true));
		Print printFail = new Print(new Boolean(false));
		Print printP = new Print(new VariableAccess(identpat));
		Composition compo = new Composition(printMatch, printP);

		Case caseInstr = new Case(identname, identpat, compo, printFail);

		Environment envBefore = new Environment();

		Composition compoFirstTest = new Composition(nameAssign,caseInstr);

		try {
			Environment envAfter = compoFirstTest.instr(envBefore);
		} catch (BadInstructionException e1) {
			e1.printStackTrace();
		}

		//System.out.println(envAfter.memory.toString());
		///////////////////////////////////////////////
		/* TEST MATCH : true expected
		local(N) {
			N = [1 2]
			case N 
				of [a b] { print(true)}			<===
				else {print(false)}
		}
		 */
		System.out.println("Second Test for Pattern Matching : expected to print \"boolean:true\"");
		Identifier identname2 = new Identifier("N");

		Identifier one2 = new Identifier("a");
		Identifier two2 = new Identifier("b");
		AST[] values2 = new AST[2];
		values2[0] = one2;
		values2[1] = two2;

		PatternArray patternArray2 = new PatternArray(values2);

		AST[] nameArray2 = {new Integer(1), new Integer(2)};
		ArrayDef nameAssign2 = new ArrayDef(identname2, nameArray2);

		Print printMatch2 = new Print(new Boolean(true));
		Print printFail2 = new Print(new Boolean(false));

		Case caseInstr2 = new Case(identname2, patternArray2, printMatch2, printFail2);

		Environment envBefore2 = new Environment();

		Composition compoFirstTest2 = new Composition(nameAssign2, caseInstr2);

		try {
			Environment envAfter2 = compoFirstTest2.instr(envBefore2);
		} catch (BadInstructionException e) {
			e.printStackTrace();
		}

		//System.out.println(envAfter2.memory.toString());

		///////////////////////////////////////////////////
		/* TEST MATCH : false expected
		local(N) {
			N = 1
			case N 
				of [a b] then print(true)
				else print(false)   			<===
		}
		 */	
		System.out.println("Third Test for Pattern Matching : expected to print \"boolean:false\"");
		Identifier identname3 = new Identifier("N");
		Identifier identpat3 = new Identifier("P");

		Identifier one3 = new Identifier("a");
		Identifier two3 = new Identifier("b");
		AST[] values3 = new AST[2];
		values3[0] = one3;
		values3[1] = two3;

		PatternArray patternArray3 = new PatternArray(values3); 

		VariableAssign nameAssign3 = new VariableAssign(identname3, new Integer(1));

		Print printMatch3 = new Print(new Boolean(true));
		Print printFail3 = new Print(new Boolean(false));

		Case caseInstr3 = new Case(identname3, patternArray3, printMatch3, printFail3);

		Environment envBefore3 = new Environment();

		Composition compoFirstTest3 = new Composition(nameAssign3,caseInstr3);


		try {
			Environment envAfter3 = compoFirstTest3.instr(envBefore3);
		} catch (BadInstructionException e) {
			e.printStackTrace();
		}


	}
}
